<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>12利用canvas绘制图片</title>
</head>
<body>
    <canvas id="oCanvas" width=500 height=600 style="border:2px solid black"></canvas>
    
</body>
<script>
    // 1.通过id获取canvas对象
    var canvas = document.getElementById("oCanvas");
    // 2.通过canvas对象获取2d画笔对象
    var ctx = canvas.getContext('2d');
    // 3.通过画笔对象绘图


    var image = new Image();
    image.src='../images/1.jpg';
    // 图片异步加载
    image.onload = function(){
        // 图片加载完毕
        ctx.drawImage(image,10,10,400,150);
    }

    



</script>

</html>